import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';

class CustomTextFormField extends StatelessWidget {
  const CustomTextFormField({
    Key? key,
    this.alignment,
    this.title,
    this.width,
    this.height =55,
    this.controller,
    this.focusNode,
    this.autofocus = false,
    this.expand = false,
    this.textStyle,
    this.obscureText = false,
    this.textInputAction = TextInputAction.next,
    this.textInputType = TextInputType.text,
    this.maxLines,
    this.hintText,
    this.hintStyle,
    this.prefix,
    this.prefixConstraints,
    this.suffix,
    this.suffixConstraints,
    this.contentPadding,
    this.borderDecoration,
    this.fillColor,
    this.filled = true,
    this.validator,
    this.onFieldSubmitted,
  }) : super(
          key: key,
        );

  final Alignment? alignment;

  final double? width;
  final double? height;

  final TextEditingController? controller;

  final FocusNode? focusNode;

  final bool? autofocus;
  final bool? expand;

  final TextStyle? textStyle;

  final bool? obscureText;

  final TextInputAction? textInputAction;

  final TextInputType? textInputType;

  final int? maxLines;


  final String? hintText;

  final TextStyle? hintStyle;

  final Widget? prefix;

  final BoxConstraints? prefixConstraints;

  final Widget? suffix;

  final BoxConstraints? suffixConstraints;

  final EdgeInsets? contentPadding;

  final InputBorder? borderDecoration;

  final Color? fillColor;

  final bool? filled;
  final String? title;

  final FormFieldValidator<String>? validator;
  final Function(String)? onFieldSubmitted;

  @override
  Widget build(BuildContext context) {
    return alignment != null
        ? Align(
            alignment: alignment ?? Alignment.center,
            child: textFormFieldWidget,
          )
        : textFormFieldWidget;
  }

  Widget get textFormFieldWidget => Column(
    children: [
      if(title != null)
        Align(
          alignment: Alignment.centerRight,
          child: Padding(
            padding: const EdgeInsets.all(4.0),
            child: Text(title!,style: theme.textTheme.bodySmall!.copyWith(fontSize: 16),),
          ),
        ),
        if(expand == true)
        Expanded(
          child: SizedBox(
              width: width ?? double.maxFinite,
              child: TextFormField(
                controller: controller,
                focusNode: focusNode,
                autofocus: autofocus!,
                expands: expand??true,
                //style: textStyle ?? CustomTextStyles.labelLargeOnPrimary,
                obscureText: obscureText!,
                textAlignVertical:TextAlignVertical.top ,
                textInputAction: textInputAction,
                onFieldSubmitted:onFieldSubmitted,
                keyboardType: textInputType,
                maxLines: maxLines,
                minLines: null,
                decoration: InputDecoration(
                  hintText: hintText ?? "",
                  prefixIcon: prefix,
                  prefixIconConstraints: prefixConstraints,
                  suffixIcon: suffix,
                  suffixIconConstraints: suffixConstraints,
                  isDense: true,
                  contentPadding: contentPadding ??
                      EdgeInsets.symmetric(
                        horizontal: 12.h,
                        vertical: 15.v,
                      ),
                  fillColor: fillColor,
                  filled: filled,
                ),
                validator: validator,
              ),
            ),
        )
      else
          SizedBox(
            width: width ?? double.maxFinite,
            child: TextFormField(
              controller: controller,
              focusNode: focusNode,
              autofocus: autofocus!,
              expands: expand??true,
              //style: textStyle ?? CustomTextStyles.labelLargeOnPrimary,
              obscureText: obscureText!,
              textInputAction: textInputAction,
              onFieldSubmitted:onFieldSubmitted,
              keyboardType: textInputType,
              maxLines: maxLines,
              minLines: null,
              decoration: InputDecoration(
                hintText: hintText ?? "",
                prefixIcon: prefix,
                prefixIconConstraints: prefixConstraints,
                suffixIcon: suffix,
                suffixIconConstraints: suffixConstraints,
                isDense: true,
                //border: InputBorder.none,
                //disabledBorder: InputBorder.none,
                //enabledBorder: InputBorder.none,
                //errorBorder: InputBorder.none,
                //focusedBorder: InputBorder.none,
                //focusedErrorBorder: InputBorder.none,
                contentPadding: contentPadding ??
                    EdgeInsets.symmetric(
                      horizontal: 12.h,
                      vertical: 15.v,
                    ),
                fillColor: fillColor,
                filled: filled,
              ),
              validator: validator,
            ),
          ),
    ],
  );
  //InputDecoration get decoration => ;
}
